package com.pilipili.zeus.statistics.schedule;

import com.pilipili.zeus.statistics.service.DailyService;
import com.pilipili.zeus.statistics.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class ScheduleTask {
    @Autowired
    private DailyService dailyService;
    /**
     * 每天1点执行一次(cron = "* * 1 * * ?")
     * cron默认取得当前年,SpringBoot只写6位
     */
    @Scheduled(cron = "* * 1 * * ?")
    public void task1() {
        dailyService.registerCount(DateUtil.formatDate(DateUtil.addDays(new Date(), -1)));
        System.out.println("统计数据更新完毕");
    }
}
